package com.edu.app.mapper.linkmappers;

import com.edu.app.bean.core.SysCustomer;
import com.edu.app.bean.linkbeans.SysCustomerLesson;
import com.edu.app.model.CustomerLessonModel;
import com.edu.app.util.AppBaseMapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SysCustomerLessonMapper extends AppBaseMapper<SysCustomerLesson> {
    @Select("SELECT DISTINCT t2.* FROM S_CUSTOMER t1 INNER JOIN S_CUSTOMER_LESSON t2 on t1.ID = t2.CUSTOMER_ID INNER " +
            "JOIN S_LIST_OF_VALUE t3 ON t2.LESSON_ID = t3.ID " +
            "WHERE t1.id = #{id} AND (t3.type like '%S_LOV_LESSON%')")
    List<SysCustomerLesson> getLessonByCustomerId(Integer id);

    @Select("SELECT DISTINCT t2.id, t3.value as lesson, t2.points, t2.start_date, t2.end_date FROM S_CUSTOMER t1 INNER JOIN S_CUSTOMER_LESSON t2 on t1.ID = t2.CUSTOMER_ID INNER " +
            "JOIN S_LIST_OF_VALUE t3 ON t2.LESSON_ID = t3.ID " +
            "WHERE t1.id = #{id} AND (t3.type like '%S_LOV_LESSON%')")
    List<CustomerLessonModel> getCustomerLessonModelByCusId(Integer id);

    @Select("SELECT DISTINCT t1.* FROM S_CUSTOMER t1 INNER JOIN S_CUSTOMER_LESSON t2 on t1.ID = t2.CUSTOMER_ID INNER " +
            "JOIN S_LESSON t3 ON t2.LESSON_ID = t3.ID " +
            "WHERE t3.id = #{id}")
    List<SysCustomer> getCustomerByLessonId(Integer id);

    //注：传参数到Mapper层，当参数超过两个以上的时候，注意使用@Param标注
    @Select("SELECT * FROM S_CUSTOMER_LESSON WHERE customer_id = #{customer_id} and lesson_id = #{lesson_id}")
    SysCustomerLesson getCustomerLesson(@Param("customer_id") Integer customer_id, @Param("lesson_id") Integer lesson_id);

    /*@Select("SELECT t3.* FROM S_CUSTOMER t1 INNER JOIN S_CUSTOMER_ACTIVITY t2 on t1.ID = t2.CUSTOMER_ID INNER " +
            "JOIN S_ACTIVITY t3 on t2.ACTIVITY_ID = t3.ID " +
            "WHERE t1.id = #{id} ORDER BY t3.time DESC")
    List<SysActivity> getCustomerActivityByPage(Integer id);*/

    @Select("DELETE FROM S_CUSTOMER_LESSON WHERE lesson_id = #{lesson_id}")
    Integer deleteCustomerLessonByLessonId(Integer lesson_id);

    @Select("DELETE FROM S_CUSTOMER_LESSON WHERE customer_id = #{customer_id}")
    Integer deleteCustomerLessonByCustomerId(Integer customer_id);
}
